using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Storage;
using MicroMsg.UI.Util;
using Microsoft.Phone.Controls;
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
namespace MicroMsg.UI.Page
{
	public class HighQualityHeadImgView : BasePage
	{
		private const string TAG = "HighQualityHeadImgView";
		private string mStrUserName;
		private double dStartWidth = 110.0;
		private double dEndWidth = 480.0;
		private double dStartHeight = 110.0;
		private double dEndHeight = 480.0;
		private double dStartLeft = 20.0;
		private double dEndLeft;
		private double dStartTop = 48.0;
		private double dEndTop = 150.0;
		private bool mBIsFirstPageIn = true;
		private bool bIsFirstLoaded = true;
		private bool bIsGoingBack;
		private bool mBIsNeedLoadHDImgAsyn;
		internal Canvas LayoutRoot;
		internal Button btnBackGround;
		internal Canvas cavasImgHolder;
		internal Image imgBigHead;
		internal PerformanceProgressBar progressBar;
		internal TextBlock txtProgressTitle;
		private bool _contentLoaded;
		public HighQualityHeadImgView()
		{
			this.InitializeComponent();
			base.add_Loaded(new RoutedEventHandler(this.HighQualityHeadImgView_Loaded));
			base.add_Unloaded(new RoutedEventHandler(this.HighQualityHeadImgView_Unloaded));
		}
		protected override void OnPageIn(object[] object_0)
		{
			Log.smethod_5("HighQualityHeadImgView", "OnPageIn");
			if (object_0 != null && 2 <= object_0.Length && object_0[0] is ImageSource && object_0[1] is string)
			{
				this.imgBigHead.set_Source(object_0[0] as ImageSource);
				this.mStrUserName = (object_0[1] as string);
			}
			if (3 == object_0.Length && object_0[2] is Point)
			{
				Point point = (Point)object_0[2];
				this.dStartLeft = point.get_X();
				this.dStartTop = point.get_Y();
				return;
			}
			if (3 == object_0.Length && object_0[2] is Rect)
			{
				Rect rect = (Rect)object_0[2];
				this.dStartLeft = rect.get_Left();
				this.dStartTop = rect.get_Top();
				this.dStartWidth = rect.get_Width();
				this.dStartHeight = rect.get_Height();
			}
		}
		protected override void OnPageOut()
		{
			Log.smethod_5("HighQualityHeadImgView", "OnPageOut");
		}
		private void HighQualityHeadImgView_Unloaded(object sender, RoutedEventArgs e)
		{
		}
		private void HighQualityHeadImgView_Loaded(object sender, RoutedEventArgs e)
		{
			if (this.bIsFirstLoaded)
			{
				this.bIsFirstLoaded = false;
				this.getBigHeadImg(this.mStrUserName);
			}
		}
		private void getBigHeadImg(string strUserName)
		{
			if (string.IsNullOrEmpty(strUserName))
			{
				return;
			}
			this.imgBigHead.set_Visibility(0);
			this.startAnimation();
		}
		private void getBigHeadImgCallBack(bool bSuccess, string usrName, BitmapImage bitmapImage_0)
		{
			if (bSuccess)
			{
				if (!(usrName == this.mStrUserName))
				{
					return;
				}
				Log.smethod_5("HighQualityHeadImgView", "get HD head image success msg got" + usrName);
				this.releaseProgress();
				try
				{
					this.imgBigHead.set_Source(bitmapImage_0);
					return;
				}
				catch (Exception ex)
				{
					Log.smethod_5("HighQualityHeadImgView", "imgBigHead.Source = bm  Exception:" + ex.get_Message());
					return;
				}
			}
			if (usrName == this.mStrUserName)
			{
				Log.smethod_5("HighQualityHeadImgView", "get HD head image failed");
				this.releaseProgress();
			}
		}
		private void setProgress()
		{
			this.progressBar.IsIndeterminate = true;
			this.txtProgressTitle.set_Visibility(0);
		}
		private void releaseProgress()
		{
			this.progressBar.IsIndeterminate = false;
			this.txtProgressTitle.set_Visibility(1);
		}
		private void startAnimation()
		{
			Storyboard storyboard = new Storyboard();
			DoubleAnimation doubleAnimation = this.createAnimation(this.dStartWidth, this.dEndWidth, this.imgBigHead, "Width", 200u);
			storyboard.get_Children().Add(doubleAnimation);
			doubleAnimation = this.createAnimation(this.dStartHeight, this.dEndHeight, this.imgBigHead, "Height", 200u);
			storyboard.get_Children().Add(doubleAnimation);
			doubleAnimation = this.createAnimation(this.dStartLeft, this.dEndLeft, this.imgBigHead, "(Canvas.Left)", 200u);
			storyboard.get_Children().Add(doubleAnimation);
			doubleAnimation = this.createAnimation(this.dStartTop, this.dEndTop, this.imgBigHead, "(Canvas.Top)", 200u);
			storyboard.get_Children().Add(doubleAnimation);
			storyboard.add_Completed(new EventHandler(this.sb_Completed));
			storyboard.Begin();
		}
		private void endAnimation()
		{
			if (this.bIsGoingBack)
			{
				return;
			}
			this.bIsGoingBack = true;
			Storyboard storyboard = new Storyboard();
			DoubleAnimation doubleAnimation = this.createAnimation(this.dEndWidth, this.dStartWidth, this.imgBigHead, "Width", 200u);
			storyboard.get_Children().Add(doubleAnimation);
			doubleAnimation = this.createAnimation(this.dEndHeight, this.dStartHeight, this.imgBigHead, "Height", 200u);
			storyboard.get_Children().Add(doubleAnimation);
			doubleAnimation = this.createAnimation(this.dEndLeft, this.dStartLeft, this.imgBigHead, "(Canvas.Left)", 200u);
			storyboard.get_Children().Add(doubleAnimation);
			doubleAnimation = this.createAnimation(this.dEndTop, this.dStartTop, this.imgBigHead, "(Canvas.Top)", 200u);
			storyboard.get_Children().Add(doubleAnimation);
			storyboard.add_Completed(new EventHandler(this.sb_end_Completed));
			storyboard.Begin();
		}
		private void sb_Completed(object sender, EventArgs e)
		{
			if (string.IsNullOrEmpty(this.mStrUserName))
			{
				return;
			}
			if (!HDheadImgMgr.hasHDheadImg(this.mStrUserName))
			{
				return;
			}
			Contact contact = StorageMgr.contact.method_0(this.mStrUserName);
			if (contact == null)
			{
				BitmapImage headImage = HDheadImgMgr.getHeadImage(this.mStrUserName);
				if (headImage != null)
				{
					this.imgBigHead.set_Source(headImage);
				}
				else
				{
					this.mBIsNeedLoadHDImgAsyn = true;
				}
			}
			else
			{
				if (contact.nHasWeiXinHdHeadImg != 0u || contact.strUsrName == AccountMgr.strUsrName)
				{
					BitmapImage headImage2 = HDheadImgMgr.getHeadImage(this.mStrUserName);
					if (headImage2 != null)
					{
						this.imgBigHead.set_Source(headImage2);
					}
					else
					{
						this.mBIsNeedLoadHDImgAsyn = true;
					}
				}
			}
			if (this.mBIsNeedLoadHDImgAsyn && HDheadImgMgr.getHeadImage(this.mStrUserName, new onGetHDheadImgCallback(this.getBigHeadImgCallBack)))
			{
				this.setProgress();
			}
		}
		private void sb_end_Completed(object sender, EventArgs e)
		{
			base.GoBack();
		}
		private Storyboard playStoryboard(double from, double double_0, UIElement target, string property, uint duration)
		{
			Storyboard storyboard = new Storyboard();
			DoubleAnimation doubleAnimation = new DoubleAnimation();
			doubleAnimation.set_From(new double?(from));
			doubleAnimation.set_To(new double?(double_0));
			doubleAnimation.set_Duration(TimeSpan.FromMilliseconds(duration));
			storyboard.set_Duration(TimeSpan.FromMilliseconds(duration));
			Storyboard.SetTarget(storyboard, target);
			Storyboard.SetTargetProperty(storyboard, new PropertyPath(property, new object[0]));
			storyboard.get_Children().Add(doubleAnimation);
			if (storyboard != null)
			{
				storyboard.Begin();
			}
			return storyboard;
		}
		private DoubleAnimation createAnimation(double from, double double_0, UIElement target, string property, uint duration)
		{
			new Storyboard();
			DoubleAnimation doubleAnimation = new DoubleAnimation();
			doubleAnimation.set_From(new double?(from));
			doubleAnimation.set_To(new double?(double_0));
			doubleAnimation.set_Duration(TimeSpan.FromMilliseconds(duration));
			Storyboard.SetTarget(doubleAnimation, target);
			Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath(property, new object[0]));
			return doubleAnimation;
		}
		private void btnBackGround_Click(object sender, RoutedEventArgs e)
		{
			this.endAnimation();
		}
		protected override void OnBackKeyPress(CancelEventArgs cancelEventArgs_0)
		{
			cancelEventArgs_0.set_Cancel(true);
			this.endAnimation();
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/Contact/HighQualityHeadImgView.xaml", 2));
			this.LayoutRoot = (Canvas)base.FindName("LayoutRoot");
			this.btnBackGround = (Button)base.FindName("btnBackGround");
			this.cavasImgHolder = (Canvas)base.FindName("cavasImgHolder");
			this.imgBigHead = (Image)base.FindName("imgBigHead");
			this.progressBar = (PerformanceProgressBar)base.FindName("progressBar");
			this.txtProgressTitle = (TextBlock)base.FindName("txtProgressTitle");
		}
	}
}
